import logging

from django.conf import settings 

from brispon import brispon_setting as bs
from brispon.models import Event

def get_contexts(request):
    mobile = request.is_mobile
    m_current_page = ''
    current_page = ''
    path = request.path_info.split('/')
    full_path = request.get_host() + request.get_full_path()
    sevents = Event.objects.get_sevents()
    
    if not mobile:
        current_page = path[1]
    else:
        if len(path) > 2:
            m_current_page = path[2]
    local_test = getattr(bs, 'LOCAL_TEST', False)
    server_test = getattr(bs, 'SERVER_TEST', False)
    return {
            'mobile': mobile,
            'local_test': local_test,
            'server_test': server_test,
            'current_page':current_page,
            'm_current_page':m_current_page,
            'full_path':full_path,
            'sevents':sevents,
            }

def get_client_ip(request):
    x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
    if x_forwarded_for:
        ip = x_forwarded_for.split(',')[-1].strip()
    else:
        ip = request.META.get('REMOTE_ADDR')
    return ip